import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * Write a description of class EnemyTank here.
 * 
 * @author : Shreya 
 * @version (a version number or a date)
 */
public class EnemyTank extends Tank
{

    private TankWorld tankWorld;
   /* private int bd;      
    private int xPos;
    private int yPos;
    protected int bulletSpeed;*/
    private int reloadDelayCount;
    private static final int GUNRELOADTIME = 70;
    public EnemyTank()
    {
        super();
        
    }
    
    public void act() 
   {
        movearound();
        fire();
        reloadDelayCount++;
        checkCollision();
       // getWorld().addObject(new Bullet(), getX() + 2, getY() - 2);
        //getWorld().addObject(new Bullet(bulletSpeed, getX(), getY(), +2), getX() + 2, getY() - 2);
       // Explosion();
    }    

    public void movearound()
    {
        move(2);
        if(Greenfoot.getRandomNumber(100) < 10)
        {
           turn(Greenfoot.getRandomNumber(150)-45); 
        }
        if (getX() <= 5 || getX() >= getWorld().getWidth() -5)
        {
            turn(180);
        }
        if (getY() <= 5 || getY() >= getWorld().getHeight() -5)
        {
            turn(180);
        }
       
    }
    
    private void fire()
    {
        if(reloadDelayCount >= GUNRELOADTIME)
        {
        EnemyBullet bullet = new EnemyBullet();
        getWorld().addObject(bullet, getX() + 2, getY() - 2);
        bullet.setRotation(getRotation());
        reloadDelayCount = 0;
        }
    }
    
    private void checkCollision()
    {
        Bullet a = (Bullet)getOneIntersectingObject(Bullet.class);
        if (a != null)
        {
            World world = getWorld();
            world.addObject(new Explosion(), getX(), getY());
            world.removeObject(a);
            world.removeObject(this);
            
        }
    }
}